package com.korovyansk.mapsproto.beans;

public class RectArea {
	
	public final Position position;
	public final Size size;
	
	public RectArea(Position position, Size size) {
		this.position = position;
		this.size = size;
	}
	
	public static RectArea makeFromCenter(Position center, Size size){
		return new RectArea(new Position(center.x - size.width / 2, center.y - size.height / 2), size);
	}

	@Override
	public boolean equals(Object o) {
		if(o != null && o instanceof RectArea){
			RectArea otherRectArea = (RectArea)o;
			return position.equals(otherRectArea.position) && size.equals(otherRectArea.size);
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return position.hashCode() * 3 + size.hashCode() * 5;
	}
	
	@Override
	public String toString() {
		return String.format("[%d,%d,%d,%d]", position.x, position.y, position.x + size.width, position.y + size.height);
	}
	
	public Position getCenter(){
		return new Position(position.x + size.width / 2, position.y + size.height / 2);
	}
}
